package com.rongke.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.mapper.UserMapper;
import com.rongke.model.InspectionRecord;
import com.rongke.model.User;
import com.rongke.service.UserService;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Service;

/**
 * @UserServiceImpl
 * @ServiceImpl
 * @version : Ver 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    /**
     * 判断当前会话是否过期
     * @return
     */
    @Override
    public Boolean checkTimeOut() {
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        long totalTime = System.currentTimeMillis() - session.getStartTimestamp().getTime();//会话历经时长
        long timeOut = session.getTimeout();
        if (totalTime - timeOut > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public User selectByPhone(String phoneNo) {
        EntityWrapper<User> ew = new EntityWrapper<>();
        ew.eq("phone", phoneNo);

        List<User> userList = baseMapper.selectList(ew);
        if (null == userList || userList.size() == 0) {
            return null;
        }

        return userList.get(0);
    }
}
